<?php

require("include/functions.inc");

/*
header("Content-Type: text/plain");
foreach (array_keys($_POST) as $k) {
  print "$k = {$_POST[$k]}\n";
}
exit;
*/

if($ime == '') {
	header("location:bileti.php?registerime=0");
  	exit;
} else if($prezime == '') {
	header("location:bileti.php?registerprezime=0&ime=$ime");
  	exit;
} else if($email == '') {
	header("location:bileti.php?registeremail=0&ime=$ime&prezime=$prezime");
  	exit;
} else if($email != '') {
	if (!eregi("^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+"."@"."[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\."."[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$", $email)) {
		header("location:bileti.php?registervalidemail=0&ime=$ime&prezime=$prezime&date=".$date);
  		exit;
	}

	list ($username, $domain) = split("@", $email);

	if (!checkdnsrr($domain.".", "MX")) {
		header("location:bileti.php?registervalidemail=0&ime=$ime&prezime=$prezime");
  		exit;
	}
}
if(!$uslovi) {
	header("location:bileti.php?registeruslovi=0&ime=$ime&prezime=$prezime&email=$email&bileti=$bileti");
  	exit;
}

// connect to DB

openConnection();

// user verification

$sql = "SELECT * FROM publika WHERE email='".$email."'";
$result = mysql_query($sql)
        or die ("Greska vo proverka na email adresata! Prijavete na info@sunsblog.net");

if (mysql_num_rows($result) != 1) {
 $sqlr = "insert into publika (ime, prezime, email, bileti, pismo, uslovi, nastan, datum) values ('".$ime."','".$prezime."','".$email."','".$bileti."','".$pismo."', '".$uslovi."', '".$nastan."', now())";
 $resr = mysql_query($sqlr)
 		or die("Greska vo postavuvanje na rezervacijata. Prijavete na info@sunsblog.net");
 $subject = 'Potvrda za rezervacija REF:'.mysql_insert_id();
 $from = 'bileti@sunsblog.net';
 $admin = 'gjokica.zafirovski@blueyonder.co.uk';
 $message = '
Ve molime otpecatete ja ovaa potvrda i pokazete ja na biletarnicata koga ke gi kupuvate Vasite bileti za koncertot, najdocna do 19:00 casot, denta na koncertot 23.12.2005. Po ovoj termin, ovaa rezervacija e nevazecka.

REF:'.mysql_insert_id().'
DEN: 23.12.2005
NASTAN: Suns - Akusticen koncert
MESTO: kino Frosina MKC Skopje
POCETOK: 20:30 casot
IME: '.$ime.' '.$prezime.'
EMAIL: '.$email.'
BILETI: '.$bileti.'

Ako imate prasanja, slobodno kontaktirajte ne na bileti@sunsblog.net.

sunsblog.net
';

 sendmail($email, $subject, $message, $from);
 sendmail($admin, $subject, $message, $from);

  header("location:bileti.php?r=1");
  exit;

} else {
   
  header("location:bileti.php?registeremail=postoi&ime=$ime&prezime=$prezime");
  exit;
}

?>